<?php
declare (strict_types=1);

namespace app\admin\controller\business;

use app\common\model\BusinessCourse;
use think\facade\Request;
use app\common\service\BusinessCarousel as S;
use app\common\model\BusinessCarousel as M;

class Carousel extends \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        return $this->getAuto($this->fetch(), M::getList());
    }

    // 添加
    public function add()
    {
        $course = BusinessCourse::where('status', '=', 1)->select();
        return $this->getAuto($this->fetch('', ['course' => $course]), S::goAdd(Request::post()));
    }

    // 编辑
    public function edit($id)
    {
        $course = BusinessCourse::where('status', '=', 1)->select();
        return $this->getAuto($this->fetch('', ['model' => M::find($id), 'course' => $course]), S::goEdit(Request::post(), $id));
    }

    // 状态
    public function status($id)
    {
        return $this->getJson(S::goStatus(Request::post('status'), $id));
    }

    // 删除
    public function remove($id)
    {
        return $this->getJson(S::goRemove($id));
    }

    // 批量删除
    public function batchRemove()
    {
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
    }

    // 回收站
    public function recycle()
    {
        return $this->getAuto($this->fetch(), S::goRecycle());
    }

}
